<template>
  <div class="profile">
    <!-- 顶部导航 -->
  <van-nav-bar
  title="我的"
  left-text="返回"
  left-arrow
  @click-left="onClickLeft"
/>

  <!-- 登录注册 -->
<div @click="login" class="login">
      <img :src="userInfo.headImg" alt="" />
      <div class="info">
        <div class="name">{{ userInfo.username }}</div>
        <div ><van-icon name="phone" />
          {{ userInfo.bind }}
        </div>
      </div>
      <van-icon name="arrow" />
    </div>
      <!-- 余额/优惠/积分 -->
    <div class="counts">
      <user-info path="/balance"
        :count="$store.state.userInfo.balance"
        desc="我的余额"
        unit="元" 
      ></user-info>
      <user-info
        :count="$store.state.userInfo.discount"
        desc="我的优惠"
        unit="个"
      ></user-info>
      <user-info
        :count="$store.state.userInfo.integral"
        desc="我的积分"
        unit="分"
      ></user-info>
    </div>

      <!-- 订单/积分商城/饿了么会员 -->
    <div class="mid">
      <van-cell center is-link size="large">
      <template #title>
        <van-icon name="shopping-cart-o" />&nbsp;
        <span class="custom-title">我的订单</span>
      </template>
    </van-cell>

      <van-cell center is-link size="large">
      <template #title>
        <van-icon name="cart-circle" />&nbsp;
        <span class="custom-title">积分商城</span>
      </template>
    </van-cell>
      <van-cell center is-link size="large">
      <template #title>
        <van-icon name="vip-card-o" />&nbsp;
        <span class="custom-title">饿了么会员</span>
      </template>
    </van-cell>

      <div class="bottom" >
        <!-- 服务中心/下载饿了么app  -->
      <van-cell center is-link size="large">
      <template #title>
        <van-icon name="phone-circle-o" />&nbsp;
        <span class="custom-title">服务中心</span>
      </template>
    </van-cell>
    <van-cell center is-link size="large" to="/home/download" >
      <template #title>
        <van-icon name="down" />&nbsp;
        <span class="custom-title">下载饿了么APP</span>
      </template>
    </van-cell>
    <van-cell center is-link size="large">
      <template #title>
        <van-icon name="location-o" />&nbsp;
        <span class="custom-title">我的地址</span>
      </template>
    </van-cell>
    </div>
    </div>
</div>

</template>

<script>
// import NavBar from "../../components/navbar/NavBar.vue";
import UserInfo from "./UserInfo.vue";
import { Toast } from 'vant';
export default {
  components: { UserInfo },
  computed: {
    userInfo() {
      return this.$store.state.userInfo;
    },
  },
  methods: {
    onClickLeft() {
      Toast('返回');
      this.$router.back()
    },
    login(){
      if (window.localStorage.getItem("user_id")) {
        this.$store.commit("changeShowInfoChildren", true)
        this.$router.push("/home/info")
      }else{
        this.$router.push("/login")
      }
    }
  },
};
</script>

<style scoped lang="scss" >
.van-nav-bar{
  background: rgb(2, 182, 253,0.7)
}
.login {

  width: 100%;
  display: flex;
  padding: 10px 0;
  background: rgb(2, 182, 253,0.7);
  justify-content: space-between;
  align-items: center;
  img {
    padding-left: 10px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
  }
  .info {
    flex: 1;
    padding: 10px 0;
    display: flex;
    flex-direction: column;
    margin-left: 10px;
    color: #fff;
    justify-content: space-between;
    .name {
      font-weight: 600;
      margin-bottom: 10px;
    }
  }
}

.counts {
  display: flex;
  justify-content: space-between;
  div {
    flex: 1;
  }
}
.mid,
.bottom {
  margin-top: 15px;
}
</style>